<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="{{URL::asset('js/jquery.tablesort.js')}}"></script>
<style type="text/css">
    th {
        /*background: #f4f4f4;*/
        cursor: pointer
    }
    th.sorted,
    th:hover {
        background: #d4d4d4
    }
    th.no-sort,
    th.no-sort:hover {
        background: #f4f4f4;
        cursor: not-allowed
    }
    th.sorted.ascending:after {
        content: "  \2191"
    }
    th.sorted.descending:after {
        content: " \2193"
    }
    .disabled {
        opacity: .5
    }
</style>
<div id="page-wrapper"></div>
<script type="text/javascript">
    var now = new Date(); //当前日期 
    var nowDayOfWeek = now.getDay(); //今天本周的第几天 
    var nowDay = now.getDate(); //当前日 
    var nowMonth = now.getMonth(); //当前月 
    var nowYear = now.getYear(); //当前年 
    nowYear += (nowYear < 2000) ? 1900 : 0; //

    var lastMonthDate = new Date(); //上月日期
    lastMonthDate.setDate(1);
    lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
    var lastYear = lastMonthDate.getYear();
    var lastMonth = lastMonthDate.getMonth();

    //格式化日期：yyyy-MM-dd 
    function formatDate(date) { 
        var myyear = date.getFullYear(); 
        var mymonth = date.getMonth()+1; 
        var myweekday = date.getDate(); 

        if(mymonth < 10){ 
            mymonth = "0" + mymonth; 
        } 
        if(myweekday < 10){ 
            myweekday = "0" + myweekday; 
        } 
        return (myyear+"-"+mymonth + "-" + myweekday); 
    } 

    //获得某月的天数 
    function getMonthDays(myMonth){ 
        var monthStartDate = new Date(nowYear, myMonth, 1); 
        var monthEndDate = new Date(nowYear, myMonth + 1, 1); 
        var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24); 
        return days; 
    } 

    //获得本季度的开始月份 
    function getQuarterStartMonth(){ 
        var quarterStartMonth = 0; 
        if(nowMonth<3){ 
            quarterStartMonth = 0; 
        } 
        if(2<nowMonth && nowMonth<6){ 
            quarterStartMonth = 3; 
        } 
        if(5<nowMonth && nowMonth<9){ 
            quarterStartMonth = 6; 
        } 
        if(nowMonth>8){ 
            quarterStartMonth = 9; 
        } 
        return quarterStartMonth; 
    } 

    //获得本周的开始日期 
    function getWeekStartDate() { 
        var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek); 
        return formatDate(weekStartDate); 
    } 

    //获得本周的结束日期 
    function getWeekEndDate() { 
        var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek)); 
        return formatDate(weekEndDate); 
    } 

    //获得本月的开始日期 
    function getMonthStartDate(){ 
        var monthStartDate = new Date(nowYear, nowMonth, 1); 
        return formatDate(monthStartDate); 
    } 

    //获得本月的结束日期 
    function getMonthEndDate(){ 
        var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth)); 
        return formatDate(monthEndDate); 
    }

    //获得上月开始时间
    function getLastMonthStartDate(){
        var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
        return formatDate(lastMonthStartDate); 
    }

    //获得上月结束时间
    function getLastMonthEndDate(){
        var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
        return formatDate(lastMonthEndDate); 
    }

    //获得本季度的开始日期 
    function getQuarterStartDate(){ 

        var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1); 
        return formatDate(quarterStartDate); 
    } 

    //或的本季度的结束日期 
    function getQuarterEndDate(){ 
        var quarterEndMonth = getQuarterStartMonth() + 2; 
        var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth)); 
        return formatDate(quarterStartDate); 
    }
    $('#btn_submit').on('click',function(){
        $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
        var request = {type:$('#type').val()};
        request.section = $('#section').val();
        request.group = $('#group').val();
        request.batch = $('#batch').val();
        request.start_time = $('#startTime').val();
        request.end_time = $('#endTime').val();
        request.tutor = $('#tutor').val();
        $('tbody').empty();
        $.post('regulate/submit',request,function(e){
            for(x in e){
                var html = "<tr style='text-align:center;font-size:20px;'>";
                html += '<td>'+e[x].name+'</td>';
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=1&type=1&start_time="+$('#startTime').val()+"&end_time="+$('#endTime').val()+"'>"+e[x].attendance_pre+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=2&type=1&start_time="+$('#startTime').val()+"&end_time="+$('#endTime').val()+"'>"+e[x].test_pre+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=4&type=1&start_time="+$('#startTime').val()+"&end_time="+$('#endTime').val()+"'>"+e[x].dictation_pre+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=3&type=1&start_time="+$('#startTime').val()+"&end_time="+$('#endTime').val()+"'>"+e[x].jiaxiao_pre+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=5&type=1&start_time="+$('#startTime').val()+"&end_time="+$('#endTime').val()+"'>"+e[x].zuoye_pre+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=0&type=1&start_time="+$('#startTime').val()+"&end_time="+$('#endTime').val()+"'>"+e[x].total_pre+"</a></td>";


                //周累计异常
                // var current_week_start = formatDate(new Date(nowYear, nowMonth, nowDay - nowDayOfWeek));
                // var current_week_end = formatDate(new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek)));
                // html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=1&start_time="+current_week_start+"&end_time="+current_week_end+"'>"+e[x].attendance_week+"</a></td>";
                // html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=2&start_time="+current_week_start+"&end_time="+current_week_end+"'>"+e[x].test_week+"</a></td>";
                // html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=4&start_time="+current_week_start+"&end_time="+current_week_end+"'>"+e[x].dictation_week+"</a></td>";
                // html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=3&start_time="+current_week_start+"&end_time="+current_week_end+"'>"+e[x].jiaxiao_week+"</a></td>";
                // html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=5&start_time="+current_week_start+"&end_time="+current_week_end+"'>"+e[x].zuoye_week+"</a></td>";
                // html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=0&start_time="+current_week_start+"&end_time="+current_week_end+"'>"+e[x].total_week+"</a></td>";



                //本月异常
                var current_month_start = formatDate( new Date(nowYear, nowMonth, 1));
                var current_month_end = formatDate(new Date(nowYear, nowMonth, getMonthDays(nowMonth)));
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=1&type=1&start_time="+current_month_start+"&end_time="+current_month_end+"'>"+e[x].attendance_month+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=2&type=1&start_time="+current_month_start+"&end_time="+current_month_end+"'>"+e[x].test_month+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=4&type=1&start_time="+current_month_start+"&end_time="+current_month_end+"'>"+e[x].dictation_month+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=3&type=1&start_time="+current_month_start+"&end_time="+current_month_end+"'>"+e[x].jiaxiao_month+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=5&type=1&start_time="+current_month_start+"&end_time="+current_month_end+"'>"+e[x].zuoye_month+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=0&type=1&start_time="+current_month_start+"&end_time="+current_month_end+"'>"+e[x].total_month+"</a></td>";


                //至今未处理异常
                var current_date = formatDate(new Date());
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=1&type=2&start_time=1997-01-01&end_time="+current_date+"'>"+e[x].attendance_not+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=2&type=2&start_time=1997-01-01&end_time="+current_date+"'>"+e[x].test_not+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=4&type=2&start_time=1997-01-01&end_time="+current_date+"'>"+e[x].dictation_not+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=3&type=2&start_time=1997-01-01&end_time="+current_date+"'>"+e[x].jiaxiao_not+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=5&type=2&start_time=1997-01-01&end_time="+current_date+"'>"+e[x].zuoye_not+"</a></td>";
                html += "<td><a href='/admin/regulate/detail?id="+x+"&notice_type=0&type=2&start_time=1997-01-01&end_time="+current_date+"'>"+e[x].total_not+"</a></td>";
                // html += '<td><button id="'+x+'" class="btn btn-primary" onclick="o_window(this.id);">全部详情'+'</button></td>';
                html += '</tr>';
                $('tbody').append(html);
            }
        });
    });

    function o_window(id){
        var wi = window.open('about:blank', '_blank');

        var start_time = $('#startTime').val();
        var end_time = $('#endTime').val();

        var domain = window.location.host;
        wi.location.href = 'http://'+domain+'/admin/regulate/detail?id='+id+'&start_time='+start_time+'&end_time='+end_time;
    }
</script>

<div class="box box-body">
    <table style="" class="table sortable" cellpadding="1" cellspacing="1" border="1">
        <thead>
            <tr>
                <th class="no-sort"></th>
                <th colspan="6" style="text-align: center;" class="no-sort">筛选条件下累积录入异常</th>
                <!-- <th colspan="6" style="text-align: center;" class="no-sort">周累积录入异常</th> -->
                <th colspan="6" style="text-align: center;" class="no-sort">月累积录入异常</th>
                <th colspan="6" style="text-align: center;" class="no-sort">至今未处理异常</th>
                <!-- <th rowspan="2" style="text-align: center;" class="no-sort">查看详情</th> -->
            </tr>
            <tr>
                <th style="text-align: center;">班主任</th>
                <th style="text-align: center;" class="number">考勤</th>
                <th style="text-align: center;" class="number">测试</th>
                <th style="text-align: center;" class="number">听写</th>
                <th style="text-align: center;" class="number">家校</th>
                <th style="text-align: center;" class="number">作业</th>
                <th style="font-weight: bold;font-size: 18px;" class="number">总计</th>
                <!-- <th style="text-align: center;" class="number">考勤</th>
                <th style="text-align: center;" class="number">测试</th>
                <th style="text-align: center;" class="number">听写</th>
                <th style="text-align: center;" class="number">家校</th>
                <th style="text-align: center;" class="number">作业</th>
                <th style="font-weight: bold;font-size: 18px;" class="number">总计</th> -->
                <th style="text-align: center;" class="number">考勤</th>
                <th style="text-align: center;" class="number">测试</th>
                <th style="text-align: center;" class="number">听写</th>
                <th style="text-align: center;" class="number">家校</th>
                <th style="text-align: center;" class="number">作业</th>
                <th style="font-weight: bold;font-size: 18px;" class="number">总计</th>
                <th style="text-align: center;" class="number">考勤</th>
                <th style="text-align: center;" class="number">测试</th>
                <th style="text-align: center;" class="number">听写</th>
                <th style="text-align: center;" class="number">家校</th>
                <th style="text-align: center;" class="number">作业</th>
                <th style="font-weight: bold;font-size: 18px;" class="number">总计</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

<script type="text/javascript">
    $(function() {
        $('table').tablesort().data('tablesort');
    });
    $('thead th.number').data('sortBy', function(th, td, sorter) {
        console.log(td.text());
        return parseInt(td.text(), 10);
    });
</script>
 

{{--<script src="{{URL::asset('js/moment.js')}}"></script>
<script src="{{URL::asset('vendor\laravel-admin\eonasdan-bootstrap-datetimepicker\build\js\bootstrap-datetimepicker.min.js')}}"></script>
<link rel="stylesheet" href="{{URL::asset('vendor\laravel-admin\eonasdan-bootstrap-datetimepicker\build\css\bootstrap-datetimepicker.min.css')}}">--}}



